package com.msoe.client.customwidgets;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.msoe.client.panels.MSOERPanel;
import com.msoe.client.panels.PanelMap;

public class NavigationMenu extends Composite implements ClickListener{
	
	private MSOERPanel parent;
	
	public NavigationMenu(MSOERPanel parentPanel){
		parent = parentPanel;

		Panel navPanel = new HorizontalPanel();
		navPanel.setWidth(RootPanel.get().getOffsetWidth() + "px");
			
		//Components
		Label L_title = new Label("MSOE Ride");
		L_title.addStyleDependentName("LogoText");
		L_title.setHorizontalAlignment(Label.ALIGN_RIGHT);
		
		HTML H_Home = new HTML();
		H_Home.setHTML("<a href='javascript:;'>&lt;" + "Home" + "&gt;</a>");
		H_Home.addStyleDependentName("NavLink");
		H_Home.setHorizontalAlignment(HTML.ALIGN_LEFT);
		
		HTML H_AddRide = new HTML();
		H_AddRide.setHTML("<a href='javascript:;'>&lt;" + "Add Ride" + "&gt;</a>");
		H_AddRide.addStyleDependentName("NavLink");
		H_AddRide.setHorizontalAlignment(HTML.ALIGN_LEFT);
		
		HTML H_GetRide = new HTML();
		H_GetRide.setHTML("<a href='javascript:;'>&lt;" + "Get Ride" + "&gt;</a>");
		H_GetRide.addStyleDependentName("NavLink");
		H_GetRide.setHorizontalAlignment(HTML.ALIGN_LEFT);
		
		HTML H_Settings = new HTML();
		H_Settings.setHTML("<a href='javascript:;'>&lt;" + "Change Settings" + "&gt;</a>");
		H_Settings.addStyleDependentName("NavLink");
		H_Settings.setHorizontalAlignment(HTML.ALIGN_LEFT);

		H_Home.addClickListener(this);
		H_AddRide.addClickListener(this);
		H_GetRide.addClickListener(this);
		H_Settings.addClickListener(this);

		navPanel.add(H_Home);
		navPanel.add(H_AddRide);
		navPanel.add(H_GetRide);
		navPanel.add(H_Settings);
		navPanel.add(L_title);
		
		initWidget(navPanel);
		
		setStyleName("NavBar");
	}
	
	public void onClick(Widget sender){		
		if(sender instanceof HTML){
			HTML clickedButton = ((HTML) sender);
			if(clickedButton.getText().contains("Add Ride"))
			{
				PanelMap.showPanel(parent, PanelMap.getPanel("AddRide"));
			}
			else if(clickedButton.getText().contains("Get Ride"))
			{
				PanelMap.showPanel(parent, PanelMap.getPanel("GetRide"));
			}
			else if(clickedButton.getText().contains("Change Settings"))
			{
				PanelMap.showPanel(parent, PanelMap.getPanel("AccountSettings"));
			}
			else if(clickedButton.getText().contains("Home"))
			{
				PanelMap.showPanel(parent, PanelMap.getPanel("UserHome"));
			}
		}
	}

}
